package von.seiji.cn.test;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.mail.MailUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import org.junit.Test;
import von.seiji.cn.IpUtil;
import von.seiji.cn.SelfUtil;
import von.seiji.cn.asset.Charsets;

import javax.swing.filechooser.FileSystemView;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.*;

/**
 * @author: Amasawa Seiji
 * @DateTime: 2020/12/25 14:55
 * @Description: 暂无描述
 */
public class T3 {


    @Test
    public void test01() throws IOException {
        List<String> analyzer = SelfUtil.analyzer("你好，我是亚纶比特星球的一名学生，今天不幸摔落到地球上！", true);
        System.out.println(analyzer);
        List<String> strings = SelfUtil.ikAnalyzer("你好，我是亚纶比特星球的一名学生，今天不幸摔落到地球上！", true);
        String[] strings1 = strings.toArray(new String[0]);
        System.out.println(Arrays.toString(strings1));
        System.out.println(strings);
    }

    @Test
    public void test02() {
        File file = new File(".\\src\\main\\resources\\ext.dic");
        System.out.println(file.exists());
        String absolutePath = file.getAbsolutePath();
        System.out.println(absolutePath);
        FileUtil.writeString(Charsets.LINE_SEPARATOR_WINDOWS + "摔落", file, Charset.defaultCharset());

    }

    @Test
    public void test03() {
        List<Integer> intList = Arrays.asList(2, 3, 1);
        System.out.println("before sort:\n" + intList);

        System.out.println("=========================");
        Collections.sort(intList, new Comparator<Integer>() {

            @Override
            public int compare(Integer o1, Integer o2) {
                // 返回值为int类型，大于0表示正序，小于0表示逆序
                System.out.println(o1 + "\t" + o2);
                System.out.println(intList);
                return o2 - o1;
            }
        });
        System.out.println("before sort:\n" + intList);

    }

    @Test
    public void test4() {
        String s = Arrays.asList("324", "32", 32, '3').toString();
        System.out.println(s);
    }

    @Test
    public void test5() {
        HashMap addresses = IpUtil.getAddresses("");
        System.out.println(addresses);
    }

    @Test
    public void test6() {
        List<String> strings = Arrays.asList("s, 速度快, 的, 深刻理解, 弗兰克, 的, 实际, 发生, 的, 圣诞快乐, 附近, 的, 水立方, 决胜, 巅峰, 第三方, 就, 死定了, 开发, 技术, 的");
        String[] objects = (String[]) strings.toArray();
        System.out.println(objects);
        String s = strings.toString();
        System.out.println(s);
    }

    @Test
    public void test7() {
        FileSystemView fileSystemView1 = new FileSystemView() {
            @Override
            public File createNewFolder(File containingDir) throws IOException {
                return null;
            }
        };
        System.out.println("fileSystemView1 = " + fileSystemView1.getHomeDirectory().getAbsolutePath());
        FileSystemView fileSystemView = FileSystemView.getFileSystemView();
        File homeDirectory = fileSystemView.getHomeDirectory();
        System.out.println(homeDirectory.getAbsolutePath());
    }

    @Test
    public void test8() {
        File file = new File("");
        System.out.println(file.getAbsolutePath());
        System.out.println(new File("F://tt", "user/u.html").getAbsolutePath());
        System.out.println(new File("F://tt", "user/u.html").isDirectory());

    }

    @Test
    public void test9() {
        System.out.println(FileUtil.extName("/dsf/dsfds/fds/fds/f/dsf/df/sd.ts.dsf.d"));
    }

    @Test
    public void test10() {
        String send = MailUtil.send("seiji926@163.com", "你好"
                , "XXXXXXXX+++XXXXXXXXX", false);
        System.out.println(send);
    }

    @Test
    public void test11() {
        String str = "[{\"top\":0,\"left\":0,\"bottom\":375,\"right\":500}]";
        System.out.println(str);
        String s1 = JSON.toJSONString(str);
        System.out.println(s1);
        JSONArray jsonObject = (JSONArray) JSONArray.parse(str);
        System.out.println(jsonObject);
        String s2 = JSON.toJSONString(jsonObject);
        System.out.println(s2);
        String s = jsonObject.toJSONString();
        System.out.println(s);
        List<HashMap<String, Object>> o = JSON.parseObject(str, new TypeReference<List<HashMap<String, Object>>>() {
        }.getType());
        System.out.println(o);
        System.out.println(o.size());
        o.forEach(item -> new Object() {
            @Override
            public String toString() {
                System.out.println(item);
                System.out.println(item.get("bottom"));
                return null;
            }
        }.toString());
    }

}
